#include "stdafx.h"

namespace classifier_test
{

conceptual_data_generator::conceptual_data_generator()
{
}

conceptual_data_generator::conceptual_data_generator(const conceptual_data_generator& Val)
{
}

void conceptual_data_generator::open()
{
}

void conceptual_data_generator::close()
{
}

conceptual_stream::conceptual_stream()
{
	ExactPeriod = false;
	ChangingFreq = 0;
}

const record_scheme& conceptual_stream::get_scheme() const
{
	return Generator->get_scheme();
}

conceptual_data_generator* conceptual_stream::get_generator() const
{
	return &*Generator;
}

void conceptual_stream::set_generator(conceptual_data_generator* Val)
{
	Generator = Val->clone();
}

bool conceptual_stream::get_exact_period() const
{
	return ExactPeriod;
}

void conceptual_stream::set_exact_period(bool Val)
{
	ExactPeriod = Val;
}

double conceptual_stream::get_changing_freq() const
{
	return ChangingFreq;
}

void conceptual_stream::set_changing_freq(double Val)
{
	ChangingFreq = Val;
}

void conceptual_stream::open()
{
	Generator->open();
	ConceptCount = Generator->get_concept_count();
	Time = 0;
	if (ExactPeriod) CurrentConcept = 0;
	else CurrentConcept = uniform(ConceptCount);
	NextTime = random_time(1 / ChangingFreq);
}

void conceptual_stream::close()
{
	Generator->close();
}

bool conceptual_stream::eof()
{
	return false;
}

void conceptual_stream::read(stream_record& Rec)
{
	Generator->generate(CurrentConcept, Rec);
	Rec.time = Time;
	Time += random_time(1);
	while (Time >= NextTime)
	{
		if (ExactPeriod) CurrentConcept = (CurrentConcept + 1) % ConceptCount;
		else CurrentConcept = (CurrentConcept + 1 + uniform(ConceptCount - 1)) % ConceptCount;
		NextTime += random_time(1 / ChangingFreq);
	}
}

double conceptual_stream::random_time(double Average) const
{
	if (ExactPeriod) return Average;
	return -log(1 - uniform()) * Average;
}

bool conceptual_stream::occur_in_time(double Freq) const
{
	return uniform() < 1 - exp(-Freq);
}

}
